/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-11-17
 * Time: 15:18
 */
public class Test1 {
    public String compressString (String param) {
        // write code here
        int len = param.length();
        StringBuffer stringbuffer = new StringBuffer();
        if(len == 0) {
            return stringbuffer.toString();
        }
        char tmp = param.charAt(0);
        int count = 1;
        for(int i = 1; i < len; i++) {
            char ch = param.charAt(i);
            if(tmp == ch) {
                count++;
            }else {
                stringbuffer.append(tmp);
                if(count > 1) {
                    stringbuffer.append(count);
                }
                tmp = ch;
                count = 1;
            }
        }
        stringbuffer.append(tmp);
        if(count > 1) {
            stringbuffer.append(count);
        }
        return stringbuffer.toString();
    }
}
